<?php
/**
 * The action->dynamic view file of dashboard module of ZenTaoPMS.
 *
 * @copyright   Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Chunsheng Wang <chunsheng@cnezsoft.com>
 * @package     dashboard
 * @version     $Id: action->dynamic.html.php 1477 2011-03-01 15:25:50Z wwccss $
 * @link        http://www.zentao.net
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php js::import($jsRoot . 'my.full.js');?>
<?php if($user->leadership == '1') :?>
<style>
  .dashboard-actions > a {
    display: inline-block;
    width: 40px;
    height: 20px;
    text-align: center;
    color: #999;
    border: 1px solid #999;
    line-height: 20px;
    background: #1a4f85;
    color: #fff;
  }
  .center{text-align: center}
    #faqi {
      position: absolute;
      left: 30px;
      top: 17px;
    }
    #user-search{border: 0;}
    .active-disabled{border: 0 ! important;}
    #featurebar{position: relative;padding: 0px 10px 7px;margin: 0px -20px 40px;border: 0;}
    #querybox{display: block;margin: 0}
    #selectPeriod{display: none ! important;}
  </style>
  <div id='featurebar'>
    <div class="data-wrap">
      <div id="querybox" class="">
        <style>
          .only-pick-time table {width: 100%}
          .only-pick-time table td {width: 150px}
          .only-pick-time table > tfoot .today, .only-pick-time table > thead {display: none !important;}
        </style>
        <script>
          /**
           * Format date to a string
           *
           * @param  string   format
           * @return string
           */
          Date.prototype.format = function(format)
          {
            var date =
            {
              "M+": this.getMonth() + 1,
              "d+": this.getDate(),
              "h+": this.getHours(),
              "m+": this.getMinutes(),
              "s+": this.getSeconds(),
              "q+": Math.floor((this.getMonth() + 3) / 3),
              "S+": this.getMilliseconds()
            };
            if (/(y+)/i.test(format))
            {
              format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
            }
            for (var k in date)
            {
              if (new RegExp("(" + k + ")").test(format))
              {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
              }
            }
            return format;
          }

          $(function()
          {
            $.fn.fixedDate = function()
            {
              return $(this).each(function()
              {
                var $this = $(this);
                if($this.hasClass('date-picker-up') || (!$this.hasClass('date-picker-down') && $this.offset().top + 200 > $(document.body).height()))
                {
                  $this.attr('data-picker-position', 'top-right');
                }

                if($this.val() != '' && !$this.hasClass('form-time'))
                {
                  var date = new Date(Date.parse($this.val().replace(/-/g, '/')));
                  if(!date.valueOf()) date = new Date();

                  if($this.hasClass('form-datetime')) $this.val(date.format('yyyy-MM-dd hh:mm:ss'));
                  else if($this.hasClass('form-month')) $this.val(date.format('yyyy-MM'));
                  else $this.val(date.format('yyyy-MM-dd'));
                }
                return $this;
              });
            };
            var options =
            {
              language: 'zh-cn',
              weekStart: 1,
              todayBtn:  1,
              autoclose: 1,
              todayHighlight: 1,
              startView: 2,
              forceParse: 0,
              showMeridian: 1,
              format: 'yyyy-mm-dd hh:ii'
            }
            window.datetimepickerDefaultOptions = options;

            $('.form-datetime').fixedDate().datetimepicker(options);
            $('.form-date').fixedDate().datetimepicker($.extend(options, {minView: 2, format: 'yyyy-mm-dd'}));
            $('.form-time').fixedDate().datetimepicker($.extend(options, {eleClass: 'only-pick-time', startView: 1, minView: 0, maxView: 1, format: 'hh:ii'}));
            $('.form-month').fixedDate().datetimepicker($.extend(options, {startView: 3, minView: 3, format: 'yyyy-mm'}));
          });
        </script>

        <script>
          window.chosenDefaultOptions = {no_results_text: '没有匹配的选项', disable_search_threshold: 1, search_contains: true, width: '100%', allow_single_deselect: true};
          $(document).ready(function()
          {
            $(".chosen").chosen(chosenDefaultOptions);
          });
        </script>
        <style>
          #querybox form {
            border-top: 0;
          }
          .icon-remove{font-size: 22px ! important;}
          #bysearchTab {transition: all .3s cubic-bezier(.175, .885, .32, 1); position: relative;}
          #bysearchTab.active > a {background: #fff; border: 1px solid #ddd; border-bottom: 0px; padding: 7px 10px!important; margin-bottom: -6px;}
          #bysearchTab.active > a:after {font-size: 14px; font-family: ZenIcon; content: ' \e6e2'; color: #808080}
          #featurebar .nav { position: relative;}
          #querybox {position: relative;}
          #querybox form{padding: 10px; padding-right: 40px;}
          #querybox .form-control {padding: 2px; padding: 6px 2px\0;}
          @-moz-document url-prefix() {#querybox .form-control {padding: 6px 2px;}}
          #querybox .table {border: none; table-layout: fixed;}
          #querybox .table-form td {border: none}
          #querybox .btn {padding: 5px 8px;}
          #querybox .table-form td td {padding: 2px;}
          #querybox .table .table {margin: 0;}
          .outer #querybox .table tr > th:first-child, .outer #querybox .table tr > td:first-child,
          .outer #querybox .table tr > th:last-child, .outer #querybox .table tr > td:last-child,
          .outer #querybox .table tbody > tr:last-child td {padding: 2px}
          #querybox a:hover {text-decoration: none;}
          #querybox .chosen-container .chosen-drop {min-width: 250px;!important}

          #selectPeriod {padding: 4px; height: 197px; min-width: 120px}
          #selectPeriod > .dropdown-header {background: #f1f1f1; display: block; text-align: center; padding: 4px 0; line-height: 20px; margin-bottom: 5px; font-size: 14px; border-radius: 2px; color: #333; font-size: 12px}
          #selectPeriod li > a {padding: 3px 15px; border-radius: 2px}

          #moreOrLite {position: absolute; right: 0; top: 0; bottom: 0}
          #searchlite, #searchmore {width: 50px; padding: 0 5px; line-height: 70px; text-align: center; opacity: 0.7}
          #searchlite {line-height: 127px}
          #searchform.showmore #searchmore, #searchform #searchlite {display: none;}
          #searchform.showmore #searchlite, #searchform #searchmore {display: inline-block;}
          #searchmore > i, #searchlite > i {font-size: 28px;}

          .bootbox-prompt .modal-dialog {width: 500px; margin-top: 10%;}
          #groupAndOr {display: inline-block;}

          .outer > #querybox {margin: -20px -20px 20px; border-top: none; border-bottom: 1px solid #ddd}
          .table-form td + td, .table-form th + th {padding-left: 0;}
          .search-field input.date::-webkit-input-placeholder{color: #000000; opacity: 1;}
          .search-field input.date::-moz-placeholder{color: #000000; opacity: 1;}
          .search-field input.date:-ms-input-placeholder{color: #000000; opacity: 1;}

        </style>
        <script language="Javascript">
          var dtOptions =
          {
            language: 'zh-cn',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: 'yyyy-mm-dd'
          };

          var datetimeOptions =
          {
            language: 'zh-cn',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            format: 'yyyy-mm-dd hh:ii'
          };

          $(function()
          {
            $('.date').each(function()
            {
              time = $(this).val();
              if(!isNaN(time) && time != ''){
                var Y = time.substring(0, 4);
                var m = time.substring(4, 6);
                var d = time.substring(6, 8);
                time = Y + '-' + m + '-' + d;
                $('.date').val(time);
              }
              setDateField(this, undefined, 'date');
            });

            $('.datetime').each(function()
            {
              time = $(this).val();
              if(!isNaN(time) && time != ''){
                var Y = time.substring(0, 4);
                var m = time.substring(4, 6);
                var d = time.substring(6, 8);
                var h = time.substring(8, 10);
                var i = time.substring(10, 12);
                time = Y + '-' + m + '-' + d + ' ' + h + ':' + i;
                $('.datetime').val(time);
              }
              setDateField(this, undefined, 'datetime');
            });

            $(document).on('change', '[name*=operator]', function()
            {
              if($(this).val() == 'between' && $(this).parent('td').next('td').find('input').val() != '' && $(this).parent('td').next('td').find('input').val().indexOf('$') == -1) $(this).val('<=');
            })
          });

          var params        = <?php echo json_encode($fieldParams);?>;
          var groupItems    = <?php echo $config->search->groupItems;?>;
          var setQueryTitle = '<?php echo $lang->search->setQueryTitle;?>';
          var module        = '<?php echo $module;?>';
          var actionURL     = '<?php echo $actionURL;?>';

          /**
           * Set date field
           *
           * @param  string $query
           * @return void
           */
          function setDateField(query, fieldNO, type)
          {
            var $query = $(query);
            if(fieldNO === undefined) fieldNO = $query.closest('.search-field').data('id');
            var $period = $('#selectPeriod');

            if(type == 'date') var options = dtOptions;
            if(type == 'datetime') var options = datetimeOptions;

            if(!$period.length)
            {
              $period = $("<ul id='selectPeriod' class='dropdown-menu'><li class='dropdown-header'>或  选择时间段</li><li><a href='#lastWeek'>上周</a></li><li><a href='#thisWeek'>本周</a></li><li><a href='#yesterday'>昨天</a></li><li><a href='#today'>今天</a></li><li><a href='#lastMonth'>上月</a></li><li><a href='#thisMonth'>本月</a></li><li><a href='#thisYear'>今年</a></li><li><a href='#lastYear'>去年</a></li></ul>").appendTo('body');
              $period.find('li > a').click(function(event)
              {
                var target = $('#' + $period.data('target'));
                if(target.length)
                {
                  if(target.next('input[type=hidden]').length)
                  {
                    target.next('input[type=hidden]').val($(this).attr('href').replace('#', '$'));
                    target.attr('placeholder', $(this).attr('href').replace('#', '$'));
                  }
                  else
                  {
                    target.val($(this).attr('href').replace('#', '$'));
                  }
                  $('#operator' + $period.data('fieldNO')).val('between');
                  $period.hide();
                }
                event.stopPropagation();
                return false;
              });
            }
            $query.datetimepicker('remove').datetimepicker(options).on('show', function(e)
            {
              var $e = $(e.target);
              var ePos = $e.offset();
              $period.css({'left': ePos.left + 193, 'top': ePos.top + 29, 'min-height': $('.datetimepicker').outerHeight()}).show().data('target', $e.attr('id')).data('fieldNO', fieldNO).find('li.active').removeClass('active');
              if($e.attr('placeholder'))
              {
                $period.find("li > a[href='" + $e.attr('placeholder').replace('$', '#') + "']").closest('li').addClass('active');
              }
              else
              {
                $period.find("li > a[href='" + $e.val().replace('$', '#') + "']").closest('li').addClass('active');
              }
            }).on('changeDate', function()
            {
              var opt = $('#operator' + $period.data('fieldNO'));
              var target = $('#' + $period.data('target'));
              if(target.length)
              {
                if(target.next('input[type=hidden]').length)
                {
                  target.next('input[type=hidden]').val(target.val());
                }
              }
              if(opt.val() == 'between') opt.val('<=');
              $period.hide();
            }).on('hide', function(){setTimeout(function(){$period.hide();}, 200);});
          }

          /**
           * When the value of the fields select changed, set the operator and value of the new field.
           *
           * @param  string $fieldName
           * @param  int    $fieldNO
           * @access public
           * @return void
           */
          function setField(fieldName, fieldNO)
          {
            $('#operator' + fieldNO).val(params[fieldName]['operator']);   // Set the operator according the param setting.
            $('#valueBox' + fieldNO).html($('#box' + fieldName.replace('.', '\\.')).children().clone());
            $('#valueBox' + fieldNO).children().attr({name : 'value' + fieldNO, id : 'value' + fieldNO});

            if(typeof(params[fieldName]['class']) != undefined && (params[fieldName]['class'] == 'date' || params[fieldName]['class'] == 'datetime'))
            {
              var type = params[fieldName]['class'];
              setDateField("#value" + fieldNO, fieldNO, type);
              $("#value" + fieldNO).addClass(type);   // Shortcut the width of the datepicker to make sure align with others.
              var groupItems = 3;
              var maxNO      = 2 * groupItems;
              var nextNO     = fieldNO > groupItems ? fieldNO - groupItems + 1 : fieldNO + groupItems;
              var nextValue  = $('#value' + nextNO).val();
              if(nextNO <= maxNO && fieldNO < maxNO && (nextValue == '' || nextValue == 0))
              {
                $('#field' + nextNO).val($('#field' + fieldNO).val());
                $('#operator' + nextNO).val('<=');
                $('#valueBox' + nextNO).html($('#box' + fieldName.replace('.', '\\.')).children().clone());
                $('#valueBox' + nextNO).children().attr({name : 'value' + nextNO, id : 'value' + nextNO});
                setDateField("#value" + nextNO, nextNO, type);
                $("#value" + nextNO).addClass(type);
              }
            }

            if(params[fieldName]['control'] == 'select' && (typeof(params[fieldName]['class']) == 'undefined' || params[fieldName]['class'] == 'chosen'))
            {
              $("#value" + fieldNO).addClass('chosen').chosen(chosenDefaultOptions);
            }
          }

          /**
           * Reset forms.
           *
           * @access public
           * @return void
           */
          function resetForm()
          {
            for(i = 1; i <= groupItems * 2; i ++)
            {
              $('#value' + i).val('');
              $('#value' + i).trigger("chosen:updated");
            }
          }

          /**
           * Show more fields.
           *
           * @access public
           * @return void
           */
          function showmore()
          {
            for(i = 1; i <= groupItems * 2; i ++)
            {
              if(i != 1 && i != groupItems + 1 )
              {
                $('#searchbox' + i).removeClass('hidden');
              }
            }

            $('#formType').val('more');
            $('#searchform').addClass('showmore');
          }

          /**
           * Show lite search form.
           *
           * @access public
           * @return void
           */
          function showlite()
          {
            for(i = 1; i <= groupItems * 2; i ++)
            {
              if(i != 1 && i != groupItems + 1)
              {
                $('#value' + i).val('');
                $('#searchbox' + i).addClass('hidden');
              }
            }
            $('#searchform').removeClass('showmore');
            $('#formType').val('lite');
          }

          /**
           * Save the query.
           *
           * @access public
           * @return void
           */
          function saveQuery()
          {
            bootbox.prompt(setQueryTitle, function(r)
            {
              if(!r) return;
              saveQueryLink = createLink('search', 'saveQuery');
              $.post(saveQueryLink, {title: r, module: module}, function(data)
              {
                if(data == 'success') location.reload();
              });
            });
          }

          /**
           * Execute a query.
           *
           * @param  int    $queryID
           * @access public
           * @return void
           */
          function executeQuery(queryID)
          {
            if(!queryID) return;
            location.href = createLink('search', 'buildQuery', 'queryID=' + queryID);
          }

          /**
           * Delete a query.
           *
           * @access public
           * @return void
           */
          function deleteQuery()
          {
            queryID = $('#queryID').val();
            if(!queryID) return;
            hiddenwin.location.href = createLink('search', 'deleteQuery', 'queryID=' + queryID);
          }
        </script>

        <div class="hidden">

              <span id="boxdepartment_id">
<?php echo html::select('department_id', $department_id,"", "class='form-control chosen-select searchInput'");?>
              </span>

  <span id="boxbigcategory">
<?php echo html::select('bigcategory', $bigcategory,"", "class='form-control chosen-select searchInput'");?>
              </span>

              <span id="boxid"><input type="text" name="id" id="id" value="" class="form-control searchInput">
</span>

              <span id="boxpersonnel">
               <?php echo html::select('personnel', $personnel,"", "class='form-control chosen-select searchInput'");?>
      </span>
              <span id="boxeventtime"><input type="text" name="eventtime" id="eventtime" value="" class="form-control searchInput">
</span>
        </div>
        <form method="post" id='ajaxForm' class="form-condensed">
          <table class="table table-condensed table-form" style="max-width: 1200px; margin: 0 auto">
            <tbody><tr>
              <td class="w-400px">
                <table class="table active-disabled">
                  <tbody><tr id="searchbox1" data-id="1" class="search-field "><td class="text-right w-60px"><span id="searchgroup1"><strong>第一组</strong></span><input type="hidden" name="andOr1" id="andOr1" value="AND">
                    </td><td class="w-90px"><select name="field1" id="field1" onchange="setField(this.value, 1)" class="form-control">
                        <option value="personnel" selected="selected">当事人</option>
                        <option value="id">编号</option>
                        <option value="department_id">所属部门</option>
                        <option value="eventtime">事件时间</option>
                        <option value="bigcategory">违规分类</option>

                      </select>
                    </td><td class="w-70px"><select name="operator1" id="operator1" class="form-control">
                        <option value="=" selected="selected">=</option>
                        <option value="!=">!=</option>
                        <option value=">">&gt;</option>
                        <option value=">=">&gt;=</option>
                        <option value="<">&lt;</option>
                        <option value="<=">&lt;=</option>
                        <option value="include">包含</option>
                        <option value="between">介于</option>
                        <option value="notinclude">不包含</option>
                        <option value="belong">从属于</option>
                      </select>
                    </td>
                    <td id="valueBox1">
                      <?php echo html::select('value1',$personnel,"", "class='form-control searchSelect chosen'");?>
                    </td>
                  </tr>
                  </tbody></table>
              <td class="text-center nobr"><select name="groupAndOr" id="groupAndOr" class="form-control w-60px">
                  <option value="and" selected="selected">并且</option>
                  <option value="or">或者</option>
                </select>
              </td>
              <td class="w-400px">
                <table class="table active-disabled">
                  <tbody><tr id="searchbox4" data-id="4" class="search-field "><td class="text-right w-60px"><span id="searchgroup2"><strong>第二组</strong></span><input type="hidden" name="andOr4" id="andOr4" value="AND">
                    </td><td class="w-90px"><select name="field4" id="field4" onchange="setField(this.value, 4)" class="form-control">
                        <option value="personnel" selected="selected">当事人</option>
                        <option value="id">编号</option>
                        <option value="department_id">所属部门</option>
                        <option value="eventtime">事件时间</option>
                        <option value="bigcategory">违规分类</option>

                      </select>
                    </td><td class="w-70px"><select name="operator4" id="operator4" class="form-control">
                        <option value="=" selected="selected">=</option>
                        <option value="!=">!=</option>
                        <option value=">">&gt;</option>
                        <option value=">=">&gt;=</option>
                        <option value="<">&lt;</option>
                        <option value="<=">&lt;=</option>
                        <option value="include">包含</option>
                        <option value="between">介于</option>
                        <option value="notinclude">不包含</option>
                        <option value="belong">从属于</option>
                      </select>
                    </td>
                    <td id="valueBox4">
                      <?php echo html::select('value4',$personnel,"", "class='form-control searchSelect chosen'");?>
                    </td>
                  </tr>
                  </tbody></table>
              </td>
              <td class="w-150px">
                <input type="hidden" name="module" id="module" value="">
                <input type="hidden" name="actionURL" id="actionURL" value="">
                <input type="hidden" name="groupItems" id="groupItems" value="3">
                <div class="btn-group"> <button type="submit" id="submit" class="btn-primary btn" data-loading="稍候...">搜索</button> <button type="button" class="btn" onclick="resetForm();">重置</button>
                </div>    </td>
              <td class="w-120px">
              </td>
            </tr>
            </tbody></table>
        </form>
        <script language="Javascript">
        </script>
        <iframe id="hiddenwin" name="hiddenwin" class="hidden"></iframe>
      </div>

    </div>
  </div>
<table class='table with-border'>
  <thead>
  <tr class='colhead'>
    <th class='w-150px'><?php echo $lang->process->id?></th>
    <th class='w-150px'><?php echo $lang->process->concerned?></th>
    <th class='w-150px'><?php echo $lang->process->department?></th>
    <th class='w-150px'><?php echo $lang->process->eventtime?></th>
    <th class='w-150px'><?php echo $lang->process->address?></th>
    <th class='w-150px'><?php echo $lang->process->desc?></th>
    <th class='w-150px'><?php echo $lang->process->leixing?></th>
    <th class='w-150px'><?php echo $lang->process->monitors?></th>
    <th class='w-150px'><?php echo $lang->process->operation?></th>
    <th class='w-150px'></th>
  </tr>
  </thead>
  <tbody>
  <?php foreach($process as $val) :?>
    <tr>
      <td class="center"><?php echo $val->id; ?></td>
      <td class="center"><?php echo $val->personnel; ?></td>
      <td class="center"><?php echo $val->department_name; ?></td>
      <td class="center"><?php echo $val->eventtime; ?></td>
      <td class="center"><?php echo $val->address; ?></td>
      <td class="center"><?php echo $val->m_content; ?></td>
      <td class="center"><?php echo $val->categoryname; ?></td>
      <td class="center"><?php echo $val->monitors_idcard; ?></td>
      <td class="center">
        <?php if($val->heads_confirm=='yes') :?>
          <?php echo html::a($this->createLink('process', 'particulars', "id={$val->id}"),$lang->process->view,"","data-toggle='modal' class='model'") ;?>
        <?php else :?>
          <?php echo html::a($this->createLink('process', 'follow', "id={$val->id}"),$lang->process->handling,"","data-toggle='modal' class='model'") ;?>
        <?php endif ?>
      </td>
      <td class="center">
        <?php if(($admin||$adminuser->police_number=='admin')):?>
          <a class="revocation" onclick="delprocess(<?php echo $val->id;?>)">撤销</a>
        <?php endif ?>
      </td>
    </tr>
  <?php endforeach ?>

  </tbody>
  <tfoot>
  <tr>
    <td colspan='10'> <?php
      $pager->show('right', 'full');
      ?>
    </td></tr></tfoot>
</table>
<?php endif ?>
<script>
  function delprocess(id){
    if(confirm("确定要撤销该数据吗？")){
      url = createLink('process','delprocess');
      $.ajax({
        type: "post",
        url: url,
        data: {"id":id},
        dataType: "json",
        success: function (data){
          if (data.erro=='1'){
            alert(data.data);
            location=location;
          }else {
            alert(data.data);
          }
        }

      })
    }
  }
</script>
<?php include '../../common/view/footer.html.php';?>
